package org.flexspeedup.command
{
import org.flexspeedup.model.IListOption;
import org.flexspeedup.model.Settings;
import org.flexspeedup.utils.Utils;
import org.swizframework.utils.chain.CommandChainStep;

/**
 * Parses a list model element from the settings file
 */
public class ParseXMLListModelCommand extends CommandChainStep
{

    //--------------------------------------------------------------------------
    //
    // Constructor
    //
    //--------------------------------------------------------------------------

    /**
     * Creates a new <code>ParseXMLListModelCommand</code> instance.
     */
    public function ParseXMLListModelCommand()
    {
        super();
    }

    //----------------------------------
    // elementName
    //----------------------------------
    /**
     * The element containing the list model data.
     */
    public var elementName:String;

    //----------------------------------
    // settings
    //----------------------------------
    [Inject(source="settings")]
    /**
     * settings bean
     */
    public var settings:Settings;

    //----------------------------------
    // data
    //----------------------------------
    [Bindable]
    /**
     * the parsed data.
     */
    public var data:Array;
   
    //--------------------------------------------------------------------------
    //
    //  Overridden methods - CommandChainStep
    //
    //--------------------------------------------------------------------------

    override public function execute():void
    {
        if (!elementName)
        {
            error();        
            throw (new Error("You must set an elementName"));
        }
        trace ("parse main menu");
        data = Utils.parseListModel(XML(settings[elementName]));
        
        complete();        
    }

}
}